
import 'dart:developer';
import 'dart:io';
import 'dart:ui' as ui;

import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';


class GlobalConfig{
  /// 七牛云地址
  static const String qiNiuHost = 'https://kx2.zyosoft.cn/';
}

class AppUtils{
  /// 获取视频第一帧
  static String getQiuVideoImage(String url) {
    if (url.isEmpty) {
      return "";
    }
    if (url.startsWith('http')) return url + '?vframe/jpg/offset/7/w/480/h/360';
    return GlobalConfig.qiNiuHost + url + '?vframe/jpg/offset/2';
  }

  /// 获取本地相册图片的宽高
 static Future<ui.Image> getImageSize(File file) async {
    final bytes = await file.readAsBytes();
    final image = await decodeImageFromList(bytes);
    print('=========${image.width}=======${image.height}');
    return image;
  }
  /// 检测是否弹出了自定义键盘
  static bool isShowKeyboard = false;

  /// 检查是否支持相册权限
  static Future<bool> permissionPhotos() async {
    Permission permission =  await getPhotoPermission();
    print('当前访问的权限是:${permission}');
    var status = permission.status;
    if(await status.isGranted){
      return true;
    }
    return false;
  }

  /// 检查麦克风权限、
  static Future<bool> permissionCheck(Permission permission) async {
    var status = permission.status;
    if(await status.isGranted){
      return true;
    }
    return false;
  }

  /// 返回相册权限
 static Future<Permission> getPhotoPermission() async {
    if(Platform.isAndroid){
      DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
      AndroidDeviceInfo androidInfo =  await deviceInfo.androidInfo;
      String androidVersion = androidInfo.version.release;
      if (int.parse(androidVersion.split('.')[0]) >= 13) {
        return Permission.manageExternalStorage;
      } else {
        return Permission.storage;
      }
    }
    return Permission.photos;
  }
}